<!--
 * @Description: 
 * @Author: zzj
 * @Date: 2021-10-20 14:05:11
 * @LastEditors: zzj
 * @LastEditTime: 2021-10-20 14:17:15
-->
<template>
	<div class="login">
		    <h3 style="text-align:center">登录</h3>
    <el-form :model="form" label-width="80px" size="small">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password"> </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click.prevent="loginHandler">登录</el-button>
        <el-button type="text" @click.prevent="$router.push('/register')">没有账号？注册</el-button> 
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {postJSON} from '../utils/request'
export default {
  setup() {
    
  },
  data(){
    return {
      form:{}
    }
  },
  methods:{
    loginHandler(){
      let url = "/user/login"
      postJSON(url,this.form).then(resp=>{
        let token = resp.data.token;
        localStorage.setItem('token',token);
        this.$router.push("/home")
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>